<script setup lang="ts">
import ConsultItem from './consult-item.vue'
import { patientConsultOrderList } from '@/api/consult'
import type { ConsultType } from '@/enums'
import type { patientConsultOrderItem } from '@/types/consult'
import { ref } from 'vue'

/*
   上拉加载 
      1：van-list需要加载内容包起来
      2：  
          v-model:loading
          finished:是否加载 完成
          finsished-text:加载 完成的文本内容
          @load=()=>{
            调用接口实现加载 
               加载 完成
                  a:loading的值变成false
                  b:数据要累加
                  c:判断是否加载 完成
                      如果完成 finished=true
                  d:下一页加载条件更新
          }
*/

const props = defineProps<{
  type: ConsultType
}>()
const params = {
  current: 1,
  pageSize: 10,
  type: props.type
}
const list = ref<patientConsultOrderItem[]>([])
const getData = async () => {
  params.type = props.type
  const res = await patientConsultOrderList(params)
  loading.value = false
  list.value.push(...res.data.rows)
  if (list.value.length >= res.data.total) {
    finished.value = true
  }
  params.current++
  console.log('列表', res)
}
const loading = ref(false)
const finished = ref(false)

// 删除某条数据
const delEvent = (id: string) => {
  list.value = list.value.filter(item => item.id !== id)
}
</script>

<template>
  <div class="consult-list">
    <van-list
      v-model:loading="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="getData"
    >
      <consult-item v-for="i in list" :key="i.id" :item="i" @delEvent="delEvent" />
    </van-list>
  </div>
</template>

<style lang="scss" scoped>
.consult-list {
  padding: 10px 15px;
}
</style>
